package cn.itcast.wushangxiantu.BaseAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import cn.itcast.wushangxiantu.R;
import cn.itcast.wushangxiantu.UserData.UserDuoBaoPaiHang;

public class DuoBaoPaiHangAdapter extends BaseAdapter {
    private Context context;
    private UserDuoBaoPaiHang userDuoBaoPaiHang;

    public DuoBaoPaiHangAdapter(Context context) {
        this.context = context;
    }

    public UserDuoBaoPaiHang getUserDuoBaoPaiHang() {
        return userDuoBaoPaiHang;
    }

    public void setUserDuoBaoPaiHang(UserDuoBaoPaiHang userDuoBaoPaiHang) {
        this.userDuoBaoPaiHang = userDuoBaoPaiHang;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return userDuoBaoPaiHang.getDuoBao().size();
    }

    @Override
    public Object getItem(int i) {
        return userDuoBaoPaiHang.getDuoBao().get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.adapter_duobaopaihang, null);
        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.tvName.setText(userDuoBaoPaiHang.getDuoBao().get(i).getName());
        viewHolder.tvNum.setText(userDuoBaoPaiHang.getDuoBao().get(i).getNum() + "/" + userDuoBaoPaiHang.getDuoBao().get(i).getAllnum());
        viewHolder.tvShuoMing.setText(userDuoBaoPaiHang.getDuoBao().get(i).getShuoming());
        viewHolder.tvTime.setText(userDuoBaoPaiHang.getDuoBao().get(i).getTime());
        return view;
    }

    class ViewHolder {
        public View rootView;
        public TextView tvName;
        public TextView tvNum;
        public TextView tvShuoMing;
        public TextView tvTime;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.tvName = (TextView) rootView.findViewById(R.id.tvName);
            this.tvNum = (TextView) rootView.findViewById(R.id.tvNum);
            this.tvShuoMing = (TextView) rootView.findViewById(R.id.tvShuoMing);
            this.tvTime = (TextView) rootView.findViewById(R.id.tvTime);
        }

    }
}
